package main

import (
	"fmt"
	"math/rand"
	"time"
)

type kelvin float64

// 类型为 func() (kelvin, int) 的函数
type sensorClass func() (kelvin, int)

func measureTemperature(samples int, sensor sensorClass) {
	for i := 0; i < samples; i++ {
		k, n := sensor()
		fmt.Print(n, ":")
		fmt.Printf("%vº K\n", k)
		time.Sleep(time.Second)
	}
}
func fakeSensor() (kelvin, int) {
	num := rand.Intn(151) + 150
	return kelvin(num), num
}

// 声明函数类型
func main() {
	measureTemperature(3, fakeSensor)
}
